package com.ddlaw.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ddlaw.entity.User;
import com.ddlaw.service.LawyerService;
import com.ddlaw.service.UserService;
import com.ddlaw.utils.Utils;

/**
 * 
 *@author YunLong
 *@time 下午8:45:25
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
	
	@Resource
	UserService userService;
	@Resource
	LawyerService lawyerService;
	
	@RequestMapping(value = "login", method = RequestMethod.GET)
	 public String loginV() {
		 return "user/login";
	 }
	
	@RequestMapping(value = "login", method = RequestMethod.POST)
	@ResponseBody
	 public Map<String,Object> login(String username, String password, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		if ("".equals(username) || "".equals(password)) {
			result.put("code", -1);
			result.put("msg", "账号或密码不能为空!");
			return result;
		}
		User user = userService.getByUsername(username);
		if (null != user) {
			password = Utils.getMd5(password);
			if (user.getPassword().equals(password)) {
				result.put("code", 200);
				return result;
			}
		}
		result.put("code", -2);
		result.put("msg", "用户名或密码错误！");
		return result;
	}
}
